package picounit.java.collection;

import java.util.Iterator;

import picounit.java.Factory;

class ConvertingIterator<To, T> implements Iterator<To> {
    public ConvertingIterator(Iterator<T> iterator, Factory<To, T> factory) {
        this.iterator = iterator;
        this.factory = factory;
    }

    public boolean hasNext() {
        return iterator.hasNext();
    }

    public To next() {
        return factory.create(iterator.next());
    }

    public void remove() {
        iterator.remove();
    }

    private final Iterator<T> iterator;
    private final Factory<To, T> factory;
}